//
//  AppDelegate.m
//  PilotSeries
//
//  Created by 黄立强 on 16/6/29.
//  Copyright © 2016年 leon.huang. All rights reserved.
//

#import "AppDelegate.h"
#import "PALoginVC.h"
#import <PgySDK/PgyManager.h>
#import <PgyUpdate/PgyUpdateManager.h>


@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
    // 创建窗口
    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;
    // 设置窗口的根控制器  
    self.window.rootViewController = [[PALoginVC alloc] init];
    
    [self setUpLogSys];
    [self setUpPgyer];
    [self settingNetworkingstaus];
    [self setUpToast];
    // 显示窗口
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

-(void)setUpLogSys{
    
    [DDLog addLogger:[DDTTYLogger sharedInstance]]; // TTY = Xcode console
//    [DDLog addLogger:[DDASLLogger sharedInstance]]; // ASL = Apple System Logs
    [[DDTTYLogger sharedInstance] setColorsEnabled:YES];
    DDFileLogger *fileLogger = [[DDFileLogger alloc] init]; // File Logger
    fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling
    fileLogger.logFileManager.maximumNumberOfLogFiles = 7;
    [DDLog addLogger:fileLogger];
    
}

-(void)setUpPgyer{
    
    [[PgyManager sharedPgyManager] setFeedbackActiveType:kPGYFeedbackActiveTypeThreeFingersPan];
    //启动基本SDK
    [[PgyManager sharedPgyManager] startManagerWithAppId:@"b6a139c4d0ea99500c226e6c95d62dfb"];
    //启动更新检查SDK
    [[PgyUpdateManager sharedPgyManager] startManagerWithAppId:@"b6a139c4d0ea99500c226e6c95d62dfb"];
    
    
}

-(void)settingNetworkingstaus{
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        [PAAppContext sharedInstance].netStatus =status;
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
                DDLogInfo(@"未识别的网络");
                
                break;
                
            case AFNetworkReachabilityStatusNotReachable:
                DDLogInfo(@"不可达的网络(未连接)");
                [CRToastManager showNotificationWithMessage:@"No available network , please check your setting!" completionBlock:^{
                    
                }];
                break;
                
            case AFNetworkReachabilityStatusReachableViaWWAN:
                DDLogInfo(@"2G,3G,4G...的网络");
                
                break;
                
            case AFNetworkReachabilityStatusReachableViaWiFi:
                DDLogInfo(@"wifi的网络");
                
                break;
            default:
                break;
        }
    }];
    [manager startMonitoring];
    
}

-(void)setUpToast{
    [CRToastManager setDefaultOptions:@{kCRToastNotificationTypeKey:@(CRToastTypeNavigationBar),kCRToastImageKey:[UIImage imageNamed:@"NotificationBackgroundErrorIcon"],kCRToastBackgroundColorKey:[UIColor colorWithRed:0.787 green:0.246 blue:0.272 alpha:1.000]}];
}

@end
